package com.neuedu.ssm.service.impl;

import com.neuedu.ssm.entity.Menu;
import com.neuedu.ssm.entity.MenuExample;
import com.neuedu.ssm.mapper.MenuMapper;
import com.neuedu.ssm.service.IMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * 项目：      spring-framework
 * 类名:       impl
 * 创建时间：  2024/3/22 14：31
 * 描述 :     MenuServiceImpl
 * 作者 :     张金山
 * QQ :     314649444
 * Site:      https://jshand.gitee.io
 */
@Service
public class MenuServiceImpl implements IMenuService {

    @Autowired
    MenuMapper menuMapper;



    @Override
    public List<Menu> queryList(Menu menu) {
        MenuExample example = new MenuExample();
        if(!StringUtils.isEmpty(menu.getMenuName())){
            example.createCriteria().andMenuNameLike("%"+menu.getMenuName()+"%");
        }

        return menuMapper.selectByExample(example);
    }

    @Override
    public Menu queryOne(int id) {
        return menuMapper.selectByPrimaryKey(id);
    }


    @Override
    public boolean saveOrUpdate(Menu menu) {
        int count = -1;

        if(menu.getMenuId() != null){//更新
            count = menuMapper.updateByPrimaryKeySelective(menu);
        }else{//新增
            count = menuMapper.insertSelective(menu);
        }
        return count>0;
    }

    @Override
    public boolean deleteById(int id) {
        return menuMapper.deleteByPrimaryKey(id)>0;
    }
}
